//
//  LiveCell.m
//  ProjectA_ManualGuest
//
//  Created by dingcong on 16/7/2.
//  Copyright © 2016年 丁聪. All rights reserved.
//

#import "LiveCell.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
@interface LiveCell ()
@property(nonatomic, retain)UIImageView *UserPic;

@property(nonatomic, retain)UILabel *lableOfTop;

@property(nonatomic, retain)UILabel *lableOfButtom;

@property(nonatomic, retain)UILabel *lableOfButton;
@end
@implementation LiveCell


- (void)dealloc{
    
    [_UserPic release];
    [_lableOfTop release];
    [_lableOfButtom release];
    [_buttonOfRight release];
    [_model release];
    [_lableOfButton release];
    
    [super dealloc];
    
    
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self creat];
    }
    return self;
}

- (void)creat{
    
    self.UserPic = [[UIImageView alloc]init];
    
   
    
    [self.contentView addSubview:self.UserPic];
    
    [self.UserPic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(10);
        make.leading.equalTo(self.contentView.mas_leading).offset(10);
        make.width.offset(60);
        make.height.equalTo(self.UserPic.mas_width).multipliedBy(1);
    }];
    
    self.UserPic.layer.cornerRadius = 16;
    self.UserPic.layer.masksToBounds = YES;
    
    self.lableOfTop = [[UILabel alloc]init];
    
    
    [self.contentView addSubview:self.lableOfTop];
    [self.lableOfTop mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(15);
        make.leading.equalTo(self.UserPic.mas_trailing).offset(10);
        make.width.offset(SCREEN_WIDTH - 160);
        make.height.offset(20);
    }];
    
    self.lableOfButtom = [[UILabel alloc]init];
    
    
    [self.contentView addSubview:self.lableOfButtom];
    [self.lableOfButtom mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lableOfTop.mas_bottom).offset(10);
        make.leading.equalTo(self.UserPic.mas_trailing).offset(10);
        make.width.equalTo(self.lableOfTop.mas_width);
        make.height.equalTo(self.lableOfTop.mas_height);
    }];
    UIView *viewOfLine = [[UIView alloc]init];
    
    viewOfLine.backgroundColor = [UIColor lightGrayColor];
    viewOfLine.alpha = 0.5;
    [self.contentView addSubview:viewOfLine];
    
    [viewOfLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.UserPic.mas_centerY);
        make.leading.equalTo(self.lableOfTop.mas_trailing).offset(10);
        make.width.offset(0.5);
        make.height.equalTo(self.UserPic.mas_height).offset( 4);
    }];
    
    self.buttonOfRight = [UIButton buttonWithType:UIButtonTypeCustom];
    
//    self.buttonOfRight.backgroundColor = [UIColor yellowColor];
    
    [self.contentView addSubview:self.buttonOfRight];
    
    [self.buttonOfRight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.UserPic.mas_centerY);
        make.leading.equalTo(viewOfLine.mas_trailing).offset(0);
        make.width.offset(69.5);
        make.height.equalTo(self.UserPic.mas_height);
    }];
    
    [self.buttonOfRight setImage:[UIImage imageNamed:@"shafa"] forState:UIControlStateNormal];
    
    [self.buttonOfRight addTarget:self action:@selector(Change:) forControlEvents:UIControlEventTouchUpInside];
    _lableOfButton = [[UILabel alloc]init];
    
    [self.buttonOfRight addSubview:_lableOfButton];
    
     [_lableOfButton mas_makeConstraints:^(MASConstraintMaker *make) {
         make.bottom.equalTo(self.buttonOfRight.mas_bottom).offset(0);
         make.leading.equalTo(self.buttonOfRight.mas_leading).offset(0);
         make.height.equalTo(self.buttonOfRight.mas_height).multipliedBy(1.0 / 4.0);
         make.width.equalTo(self.buttonOfRight.mas_width);
        
     }];
    _lableOfButton.text = @"抢占沙发";
    _lableOfButton.font = [UIFont systemFontOfSize:13];
    _lableOfButton.textAlignment = NSTextAlignmentCenter;
    _lableOfButton.textColor = [UIColor redColor];
    [_lableOfButton release];
    [_UserPic release];
    [_lableOfButtom release];
    [_lableOfTop release];
    [viewOfLine release];
    
}

- (void)Change:(UIButton *)change{
    
    self.buttonOfRight.tintColor = [UIColor grayColor];
    self.lableOfButton.text = @"已抢占";
    self.lableOfButton.textColor = [UIColor grayColor];
    [self.buttonOfRight setImage:[UIImage imageNamed:@"wancheng"] forState:UIControlStateNormal];
}

- (void)setModel:(ModelOfLive *)model{
    
    NSLog(@"%@", model.avatar);
    [self.UserPic sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:nil];
    
    self.lableOfTop.font = [UIFont systemFontOfSize:15];
    self.lableOfButtom.font = [UIFont systemFontOfSize:11.5];
    self.lableOfButtom.textColor = [UIColor grayColor];
    self.lableOfTop.text = model.group_name;
    self.lableOfButtom.text = model.group_title;
    
    
}

@end
